package hust.music.action;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import hust.music.action.base.ActionBase;
import hust.music.entity.Dynamic;
import hust.music.entity.PlayList;
import hust.music.entity.User;
import hust.music.service.PlayListModService;
import hust.music.util.DynamicInfo;

@Controller
@Scope("session")
public class AddListAjaxAction extends ActionBase {
	
	private static final long serialVersionUID = 1L;
	
	private String listname;
	private String listdescription;
	private String flag;
	private List<DynamicInfo> lists;
	
	public List<DynamicInfo> getLists() {
		return lists;
	}
	public void setLists(List<DynamicInfo> lists) {
		this.lists = lists;
	}

	@Autowired
	private PlayListModService playListModService;
	
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}

	
	public String getListname() {
		return listname;
	}
	public void setListname(String listname) {
		this.listname = listname;
	}
	public String getListdescription() {
		return listdescription;
	}
	public void setListdescription(String listdescription) {
		this.listdescription = listdescription;
	}
	
	public String add(){
		try{
			if(playListModService.addPlayList(listname,listdescription,(User)session.get("user"))){
				flag = "1";
			}else{
			   	flag = "0";
			}
		}catch(Exception e){
			flag = e.getMessage();
		}
		   
		   return "add";
	}
	
	public String get(){
		try {
			if(session.containsKey("user")){
				lists = playListModService.getUserPlayList((User)session.get("user"));
			}else{
				flag="没有登录";
				return "get";
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			flag=e.getMessage();
		}
		return "get";
	}
}
